﻿//===================================================================================
// $$
//
//
// Code By: Code Milker V2
// Date On: 2013//
//===================================================================================


namespace Forest.Lion.Data.SqlServer.Repositories
{
    using System;

    using System.Collections.Generic;

    using System.Data;

    using System.Linq;
    using Forest.Lion.Model;

    public class InterviewRepository : BaseRepository, IInterviewRepository
    {
        public InterviewRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }
        public void Create(Interview interview)
        {
            this.GetDbSet<Interview>().Add(interview);
            this.UnitOfWork.SaveChanges();
        }

        public Interview GetInterview(Guid interviewId)
        {
            return this.GetDbSet<Interview>()
                .Where(c => c.Id == interviewId)
                .Single();
        }

        public void Update(Interview updatedInterview)
        {
            this.GetDbSet<Interview>().Attach(updatedInterview);
            this.SetEntityState(updatedInterview, updatedInterview.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid interviewId)
        {
            Interview interviewToDelete = this.GetInterview(interviewId);
            this.GetDbSet<Interview>().Remove(interviewToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IEnumerable<Interview> Find()
        {
            return this.GetDbSet<Interview>().Take(100)
                .ToList();
        }

        public IEnumerable<Interview> GetAll()
        {
            return this.GetDbSet<Interview>().Take(100)
                .ToList();
        }
    }
}
